//
//  HotRateView.m
//  WisdomZhuHai
//
//  Created by Admin on 13-9-27.
//  Copyright (c) 2013年 wyd. All rights reserved.
//

#import "HotRateView.h"

@implementation HotRateView

@synthesize hotRate;

- (id)initWithHotRate:(float)rate
{
    UIImage *starImg = [UIImage imageNamed:@"hotel/Collection.png"];//[UIImage imageNamed:@"places/star.png"];
    CGFloat width = starImg.size.width;
    self = [super initWithFrame:CGRectMake(0, 0, width*5+5, starImg.size.height+4)];
    if (self) {
        hotRate = rate;
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    UIImage *starImg = [UIImage imageNamed:@"hotel/Collection.png"];
    CGFloat width = starImg.size.width;
    if (hotRate > 5) {
        hotRate = 5;
    }
    hotRate = (int)(hotRate + 0.5);
    CGFloat x = 0;
    CGFloat y = 2;
    for (int i=0; i<=hotRate-1; i++) {
        [starImg drawInRect:CGRectMake(x, y, starImg.size.width, starImg.size.height)];
        x += width + 1;
    }
    if (hotRate - (int)hotRate > 0) {
        UIImage *halfStarImg = [UIImage imageNamed:@"hotel/Collection2.png"];
        [halfStarImg drawInRect:CGRectMake(x, y, halfStarImg.size.width, halfStarImg.size.height)];
        x += width + 1;
    }
    for (int i=5-hotRate; i>=1; i--) {
        UIImage *backStarImg = [UIImage imageNamed:@"hotel/Collection2.png"];
        [backStarImg drawInRect:CGRectMake(x, y, backStarImg.size.width, backStarImg.size.height)];
        x += width + 1;
    }
}


@end
